<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>首页</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
    <style>
        .top-panel {
            border: 1px solid #eceff9;
            border-radius: 5px;
            text-align: center;
        }

        .top-panel > .layui-card-body {
            height: 60px;
        }

        .top-panel-number {
            line-height: 60px;
            font-size: 30px;
            border-right: 1px solid #eceff9;
        }

        .top-panel-tips {
            line-height: 30px;
            font-size: 12px
        }
    </style>
</head>
<body>
<!--<div class="layuimini-container">-->
<div class="layuimini-main">

    <div class="layui-row layui-col-space15">
        <div class="layui-col-xs12 layui-col-md4">

            <div class="layui-card top-panel">
                <div class="layui-card-header">新会员(月)</div>
                <div class="layui-card-body">
                    <div class="layui-row layui-col-space5" id="member" style="font-size: 25px;line-height:50px">

                    </div>
                </div>
            </div>

        </div>
        <div class="layui-col-xs12 layui-col-md4">

            <div class="layui-card top-panel">
                <div class="layui-card-header">新留言(月)</div>
                <div class="layui-card-body">
                    <div class="layui-row layui-col-space5" id="message" style="font-size: 25px;line-height:50px">

                    </div>
                </div>
            </div>

        </div>
        <div class="layui-col-xs12 layui-col-md4">

            <div class="layui-card top-panel">
                <div class="layui-card-header">新活动(月)</div>
                <div class="layui-card-body">
                    <div class="layui-row layui-col-space5" id="activity" style="font-size: 25px;line-height:50px">

                    </div>
                </div>
            </div>

        </div>
    </div>

    <div class="layui-row layui-col-space15">
        <div class="layui-col-xs12 layui-col-md12">
            <div id="echarts-records" style="background-color:#ffffff;min-height:400px;padding: 10px"></div>
        </div>
    </div>


    <div class="layui-row layui-col-space15">
        <div class="layui-col-xs12 layui-col-md12">
            <div id="echarts-pies" style="background-color:#ffffff;min-height:300px;padding: 10px"></div>
        </div>
    </div>


</div>
<!--</div>-->
<script src="../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>
    layui.use(['layer', 'echarts'], function () {
        var $ = layui.jquery,
            layer = layui.layer,
            echarts = layui.echarts;

        //数字看板   新会员  新活动   新留言  发送异步请求 获取看板数据  数据看板
        $.get('/echarts/dashboard', function (res) {
            if (res.code == 0) {
                let dashboardData = res.data   // {member:10,activity:20,message:30}
                $('#member').html(dashboardData.member)
                $('#activity').html(dashboardData.activity)
                $('#message').html(dashboardData.message)
            }
        })


        /**
         * 报表功能
         */

        // 获取折线图数据  发送异步请求
        $.get('/echarts/lineData',function (res){

            //  res.data   [{},{},{}]
            if (res.code==0){
                let  numbers = res.data.map(lineData=>lineData.number)   // [0.0.0.]
                var echartsRecords = echarts.init(document.getElementById('echarts-records'), 'walden');
                var optionRecords = {
                    title: {
                        text: '年度会员注册走势'
                    },
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {
                            type: 'cross',
                            label: {
                                backgroundColor: '#6a7985'
                            }
                        }
                    },
                    legend: {
                        data: ['新会员']
                    },
                    toolbox: {
                        feature: {
                            saveAsImage: {}
                        }
                    },
                    grid: {
                        left: '3%',
                        right: '4%',
                        bottom: '3%',
                        containLabel: true
                    },
                    xAxis: [
                        {
                            type: 'category',
                            boundaryGap: false,
                            data: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月']
                        }
                    ],
                    yAxis: [
                        {
                            type: 'value'
                        }
                    ],
                    series: [
                        {
                            name: '新会员',
                            type: 'line',
                            stack: '总量',
                            areaStyle: {},
                            data: numbers  //  动态获取
                        }
                    ]
                };
                echartsRecords.setOption(optionRecords);
            }

        })



        /**
         * 玫瑰图表
         */

        $.get('/echarts/rose',function (res){
            if (res.code==0){
                var echartsPies = echarts.init(document.getElementById('echarts-pies'), 'walden');
                var optionPies = {
                    title: {
                        text: '会员等级',
                        left: 'center'
                    },
                    tooltip: {
                        trigger: 'item',
                        formatter: '{a} <br/>{b} : {c} ({d}%)'
                    },
                    legend: {
                        orient: 'vertical',
                        left: 'left',
                        data: ['普通会员', '黄金会员', '白金会员', '钻石会员']
                    },
                    series: [
                        {
                            name: '访问来源',
                            type: 'pie',
                            radius: '55%',
                            center: ['50%', '60%'],
                            roseType: 'radius',
                            data: res.data,
                            emphasis: {
                                itemStyle: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ]
                };
                echartsPies.setOption(optionPies);
            }
        })


        // echarts 窗口缩放自适应
        window.onresize = function () {
            echartsRecords.resize();
        }

    });
</script>
</body>
</html>
